package KeTangLian;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Scanner;

import javax.management.Query;

public class Demo2 {
	public static void main(String[] args) { 
		//String sqlString="UPDATE student SET name='126' WHERE id=2";
		//int result=DBManager.excuteUpdate(sqlString);
		//System.out.println(result>0?"成功":"失败");
		
		//String sqlString1="insert into student values(1,'acc','女')";
		//int result1=DBManager.excuteUpdate(sqlString1);
		//System.out.println(result1>0?"成功":"失败");
		
		//String sqlString2="DELETE FROM student WHERE id=100";
		//int result2=DBManager.excuteUpdate(sqlString2);
		//System.out.println(result2>0?"成功":"失败");
		
		ArrayList<Student> aList = getStudentById();
		for (Student student : aList) {
			System.out.println(student);
		}
		
	}
	public static ArrayList<Student> getStudentById() {
		String sql2string="SELECT * from student WHERE id>=3 and id<=50";
		ArrayList<Student> aList = new ArrayList<Student>();
		QueryDataResult rSet1=DBManager.excuteQuery(sql2string);
		try {
		if (rSet1.rs!=null) {
				while (rSet1.rs.next()) {
					//System.out.println(rSet1.rs.getInt("id")+"\t"+rSet1.rs.getString("name")
						//	+"\t"+rSet1.rs.getString("sex"));
					aList.add(new Student(rSet1.rs.getInt("id"), rSet1.rs.getString("name"),
							rSet1.rs.getString("sex")));
				}
			} else {
				System.out.println("没有符合的数据");
			   }
			}catch (SQLException e) {
				e.printStackTrace();
		}
		rSet1.close();
		return aList;
	}
}
